<template>
	<view>
		<image src="/static/work1.jpg" mode="" class="img_bg"></image>
		<view class="margin-t120" v-show="!isShow">
			<exam-widght :dataList='QuestionList' :index="index" @select='selectItem' @selectFinish='selectFinish' @finish='finish'
			 :numBoxType='0' :showIndexText='showIndexText' :numBoxShow='numBoxShow'>
			</exam-widght>
		</view>
		<view class="card margin-t30 margin-l20 margin-r20" v-show="isShow">
			<view class="text-center noNotice" v-show="isShow" style="margin-top: 10upx;">
				<!-- <image src="/static/notice.png" class="noticeImg"></image> -->
				<view class="font-green  text-42">{{theMessage}}</view>
			</view>
			<view class="exam" v-show="isShow">
				<view class="margin-t20" style="border-top: 1upx solid #C0C0C0; border-bottom:1upx solid #C0C0C0;width: 100%; text-align: center;">考试结果详情</view>
				<view class="" v-for="(item,index) in theAnswer" :key="index">
					<view class="">


						<view class="margin-t20">
							题目{{index+1}}{{item.questionType==0?'(单选题)':item.questionType==1?'(多选题)':item.questionType==2?'(简答题)':''}} ：{{item.fldName}}
						</view>
						<br>
						<view class="text-24" :class="item.fldAnswer==item.right?'color_green':'color_red'">
							您的答案：{{item.fldAnswer}}
						</view>
						<br>
						<view class="text-24">
							正确答案：{{item.right}}
						</view>
						<br>
						<view v-show="item.questionType==0" class="text-24">
							内容：{{item.QuestionOptionList[item.right-1].fldOptionText}}
						</view>
						<br>
						<view v-show="item.questionType==1">
							<view class="text-24" v-for=" (nitem,index) in [item.right] " :key="index">
								<view v-show="item.QuestionOptionList[nitem[0]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[0]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[1]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[1]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[2]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[2]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[3]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[3]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[4]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[4]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[5]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[5]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[6]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[6]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[7]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[7]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[8]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[8]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[9]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[9]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[10]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[10]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[11]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[11]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[12]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[12]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[13]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[13]-1].fldOptionText}}</view>
								<view v-show="item.QuestionOptionList[nitem[14]-1].fldOptionText!=''">{{item.QuestionOptionList[nitem[14]-1].fldOptionText}}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import examWidght from '@/components/Li-ExamWidght/Li-ExamWidght.vue';
	export default {
		components: {
			examWidght
		},
		data() {
			return {
				merge_id: '',
				uid: '',
				token: '',
				isShow: false,
				fldTestPaperID: undefined,
				fldTestRecordID: undefined,
				showIndexText: true, //题号文字是否显示
				numBoxShow: false,
				items: [],
				index: 0,
				numBoxType: 0,
				QuestionList: [],
				theMessage: '',
				theAnswer: [],
				result: '',
			}
		},
		onLoad(options) {
			console.log(options)
			this.uid = uni.getStorageSync('user').uid;
			this.token = uni.getStorageSync('user').token;
			this.merge_id = options.merge_id
			this.getExamDetail()
			var _this = this;
			setTimeout(function() {
				_this.getTestPaper();
			}, 100)
		},
		methods: {
			getExamDetail() {
				var _this = this
				uni.request({
					url: 'https://aqmore.sxpz.vip/AppApi/Exam/Detail?uid=' + this.uid + '&token=' + this.token +
						'&merge_id=' + this.merge_id,
					method: 'GET',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					success(res) {
						console.log(res)

						// console.log(data.QuestionList[0].fldName)
						_this.QuestionList = res.data.datas;
						if (_this.QuestionList.length > 0) {
							let title = '1/' + _this.QuestionList.length
							if (_this.QuestionList[0].type == 0)
								title += "  单选题";
							else if (_this.QuestionList[0].questionType == 1)
								title += "  多选题";
							else
								title += "  填空题";
							uni.setNavigationBarTitle({
								title: title
							});
						}
						if (res.data.code == 800) {
							_this.isShow = true
							_this.theMessage = res.data.datas.msg
							_this.theAnswer = res.data.datas.questions

						} else if (res.data.code == 200 && res.data.datas.length == 0) {
							_this.isShow = true
							_this.theMessage = "习题列表中暂未导入题库"
						}
					}
				})

			},
			getTestPaper() {
				var _this = this


			},
			//插件
			switchBoxType() {
				this.numBoxType = this.numBoxType == 0 ? 1 : 0;
			},
			jump() {
				this.index = 9;
			},
			switchIndexBox() {
				this.numBoxShow = !this.numBoxShow;
			},
			finish(item) {
				console.log("-----finish------")
				console.log(item)
				item = JSON.stringify(item)
				console.log(item)
				uni.request({
					url: 'https://aqmore.sxpz.vip/AppApi/Exam/set',
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data:{
						'uid':this.uid,
						'token':this.token,
						'merge_id':this.merge_id,
						'content':item,
					},
					success(res) {
						console.log(res)
						uni.showToast({
							title:'提交考卷成功',
							icon:'success'
						})
						setTimeout(() => {
							uni.switchTab({
								url: '../../workspace'
							})
						}, 1500)
					}
				})


			},
			selectItem(item) {
				console.log("-----selectItem------")
				console.log(item)
			},
			selectFinish(item) {
				console.log("-----selectFinish------")
				console.log(item)
				let index = item.newItem.index + 1;
				let title = index + '/' + item.newItem.total

				if (item.newItem.question.questionType == 0)
					title += "  单选题";
				else if (item.newItem.question.questionType == 1)
					title += "  多选题";
				else
					title += "  简答题";
				uni.setNavigationBarTitle({
					title: title
				});
			},

		}
	}
</script>

<style scoped>
	.exam {
		/* color: #F0F8FF; */
		font-size: 36upx;
	}

	.color_green {
		color: #00C07F;
	}

	.color_red {
		color: #FF0000;
	}
</style>
